package com.yunhuakeji.wddx.data;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import com.yunhuakeji.wddx.utils.DBHelper;

public class ResultSetData
{

	public List<Map<String, String>> getListMapByResultSet(String sql, Object[] o)
	{
		DBHelper helper = new DBHelper();
		return getListMap(helper.select(sql, o, 0));
		
	}
	private List<Map<String, String>> getListMap(ResultSet rs)
	{
		try
		{
			List<Map<String, String>> list = new ArrayList<>();
			while (rs.next())
			{
				Map<String, String> map = new HashMap<String, String>();
				for (int i = 0; i < rs.getMetaData().getColumnCount(); i++)
				{
					if (null != rs.getString(rs.getMetaData().getColumnName(i + 1)))
						map.put(rs.getMetaData().getColumnName(i + 1).toLowerCase(Locale.CHINA), rs.getString(rs.getMetaData().getColumnName(i + 1)));
					else
					{
						map.put(rs.getMetaData().getColumnName(i + 1).toLowerCase(Locale.CHINA), "");
					}
				}
				list.add(map);
			}
			return list;
		} catch (Exception e)
		{
		}
		return null;
	}
}
